


import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.InputEvent;
import java.util.ArrayList;


public class RobotTest {

	
	Application a, a1, a2;
	
	public class Position {
		public int x;
		public int y;
		
		public Position(int x, int y) {
			this.x = x;
			this.y = y;
		}
	}
	
	
	
	public static void main(String[] args) {
		
		RobotTest r = new RobotTest();
		try {
			System.out.println("test successful: " + r.testall());
		} catch (AWTException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}


	private boolean testall() throws AWTException {
		
		// play cycle 1 - play1, vir21, map21, next2
		String testname1 = "cycle1";
		ArrayList<Position> cycle1 = new ArrayList<Position>();
		cycle1.add(play1); cycle1.add(backconf); cycle1.add(help); 
		cycle1.add(back); cycle1.add(play1); cycle1.add(play2); 
		cycle1.add(back); cycle1.add(easy);
		
		if (!test(cycle1, testname1)) return false;

		// play cycle 2 - play1, vir21, map22, next2
		String testname2 = "cycle2";
		ArrayList<Position> cycle2 = new ArrayList<Position>();
		cycle2.add(edit1); cycle2.add(backedit); cycle2.add(play1);
		cycle2.add(easy); cycle2.add(normal); cycle2.add(hard);
		cycle2.add(backconf);cycle2.add(exit1);
		if (!test(cycle2, testname2)) return false;
		//	play cycle 3 - help1
		String testname3 = "cycle3";
		ArrayList<Position> cycle3 = new ArrayList<Position>();
		cycle3.add(play1); cycle3.add(vir6); cycle3.add(map5);
		if (!test(cycle3, testname3)) return false;
	
		
		return true;
	}


	// individual test conducted along points in sequence
	private boolean test(ArrayList<Position> sequence, String testname) throws AWTException {
		Robot robot = new Robot();
		a = new Application();
		for (Position p: sequence) {
			robot.delay(500);
			robot.mouseMove(p.x, p.y);
			robot.delay(500);
			robot.mousePress(InputEvent.BUTTON1_MASK);
			robot.delay(20);
			robot.mouseRelease(InputEvent.BUTTON1_MASK);
			robot.delay(500);
		}
		System.out.println("test " + testname + " done");
		
		State s = Application.getStateManager().getCurrentState();
		boolean testResult = true;
		
		if(s instanceof ConfigState) {
			if (((ConfigState)s).radioEasy.isSelected() == true || (((ConfigState)s).virusList.getSelectedIndex() == 5 && ((ConfigState)s).mapList.getSelectedIndex() == 4)) {
				testResult = true;
			}
		}
		
		if(a != null ) a.dispose();
		return testResult;
	}


	private final Position play1 = new Position(300, 230);
	private final Position backconf = new Position(30, 450);
	private final Position play2 = new Position(600, 450);
	private final Position hard= new Position(420, 450);
	private final Position back = new Position(275, 35);
	private final Position normal= new Position(340, 450);
	private final Position easy= new Position(200, 450);
	private final Position edit1 = new Position(300, 260);
	private final Position help = new Position(300, 290);
	private final Position exit1 = new Position(300, 330);
	private final Position vir6 = new Position(30, 400);
	private final Position map5 = new Position(550, 380);
	private final Position backedit = new Position(600, 450);


}